package com.xuetang9.t9.hotel.mapper;

import com.xuetang9.t9.hotel.beans.BlackList;
import com.xuetang9.t9.hotel.mapper.condition.ICondition;
import com.xuetang9.t9.hotel.mapper.sql.impl.BlackListMapperSql;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 黑名单
 * @author PANG
 */
@Repository
public interface IBlackListMapper {

    /**
     * 添加黑名单
     * @param blackList
     * @return
     */
    @Insert("INSERT INTO g_blacklist(guest_id,staff_id,black_cause) VALUES(#{guestId},#{staffId},#{blackCause})")
    int insert(BlackList blackList);

    /**
     * 删除黑名单
     * @param id
     * @return
     */
    @Delete("DELETE FROM g_blacklist WHERE black_id=#{id}")
    int delete(Integer id);

    /**
     * 更新黑名单
     * @param blackList
     * @return
     */
    @Update("UPDATE g_blacklist SET staff_id=#{staffId},black_cause=#{blackCause} WHERE black_id=#{blackId}")
    int update(BlackList blackList);

    /**
     * 检索
     * @param blackListCondition
     * @return
     */
    @SelectProvider(value = BlackListMapperSql.class,method = "selectByAll")
    @Results(
            value = {
                    @Result(
                            column = "guest_id",property = "guest",one = @One(select = "com.xuetang9.t9.hotel.mapper.IGuestMapper.selectById",fetchType = FetchType.EAGER)
                    ),
                    @Result(
                            column = "staff_id", property = "staffInfo",one = @One(select = "com.xuetang9.t9.hotel.mapper.IStaffInfoMapper.selectById",fetchType = FetchType.EAGER)
                    )
            }
    )
    List<BlackList> selectByAll(@Param("key") ICondition blackListCondition);

    /**
     * 检索总数量
     * @param blackListCondition
     * @return
     */
    @SelectProvider(value = BlackListMapperSql.class,method = "selectByCount")
    Long selectByCount(@Param("key") ICondition blackListCondition);
}
